

# 1. 编写一个计算器实现2个数的加减乘除
# 2个Entry
# 4个Button
# 1个Label

from tkinter import *
import threading
import _thread
import time



# root = Tk()
# 这只窗口大小
# root.geometry('500x500')

# 添加框体标题
# root.title('美女计算器')

#插入一张背景图
# img = PhotoImage(file='美女.png')
# label = Label(root,image=img)
# label.place(x=170,y=90)


# 创建两个输入框  (注意一个框相差20)
# entry1 = Entry(root,bd=1)
# entry1.place(x=200,y=300)
# entry2 = Entry(root,bd=1)
# entry2.place(x=200,y=320)

# 定义加减乘除的运算法则
# label3 = Label(root)
# label3.place(x=250,y=380)

# def add():
#     a = int(entry1.get())
#     b = int(entry2.get())
#     c = a + b
#     label3.config(text=f'{c}')
# def sub():
#     a = int(entry1.get())
#     b = int(entry2.get())
#     c = a - b
#     label3.config(text=f'{c}')
# def mult():
#     a = int(entry1.get())
#     b = int(entry2.get())
#     c = a * b
#     label3.config(text=f'{c}')
# def div():
#     a = int(entry1.get())
#     b = int(entry2.get())
#     c = a / b
#     label3.config(text=f'{c}')
#
# btn = Button(root,text='+',command=add)
# btn.place(x=200,y=340)
# btn = Button(root,text='-',command=sub)
# btn.place(x=240,y=340)
# btn = Button(root,text='*',command=mult)
# btn.place(x=280,y=340)
# btn = Button(root,text='/',command=div)
# btn.place(x=320,y=340)
#
#
#
# root.mainloop()    #让框体一直存在 （x按钮就是结束信号）



# 2. 编写一个时钟
# 1个Label
# 使用多线程

def foo1():
    while True:
        t = time.localtime(time.time())
        print(f'{t.tm_hour}:{t.tm_min}:{t.tm_sec}')
        label.config(text=f'{t.tm_hour}:{t.tm_min}:{t.tm_sec}')
        time.sleep(1)

def foo2():
    _thread.start_new_thread(foo1,())

root = Tk()

root.geometry('400x200')

root.title('美女时钟')

label = Label(root,text='00:00:00',font=('Arail',50))
label.place(x=50,y=50)

foo2()

root.mainloop()